package com.mall.admin.service;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.domain.CmsSubject;
import com.mall.interface1.api.CmsSubjectApi;
import com.mall.vo.MyPage;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class CmsSubjectService {
    @DubboReference
    private CmsSubjectApi cmsSubjectApi;

    /**
     * 获取全部商品专题
     * @return
     */
    public List<CmsSubject> listAll() {
        List<CmsSubject> cmsSubjects = cmsSubjectApi.getAll();
        if(CollUtil.isEmpty(cmsSubjects)){
            return new ArrayList<>();
        }
        return cmsSubjects;
    }

    /**
     * 根据专题名称分页获取商品专题
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public MyPage<CmsSubject> listByPage(Long pageNum, Long pageSize, String keyword) {
        Page<CmsSubject> page = cmsSubjectApi.getListByPage(pageNum, pageSize, keyword);
        return MyPage.init(page);
    }
}

